/** 
  国际学术会议申请列表
*/
<template>
    <div>
        <div v-if="ifShowList ===1">
            <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
                <h1 class="condition-title">国际学术会议基金申请列表</h1>
                <div class="sub-title">
                    <div class="float-right" style="display: flex;">
                        <el-button type="primary" @click="addApplication()">申请</el-button>
                        <el-button type="danger" @click="delApplication()">删除</el-button>
                    </div>
                </div>
                <edu-table
                    :pagination="false"
                    :order="true"
                    :tooltipEffect="tooltipEffect"
                    stripe
                    :data="dataList"
                    size="small"
                    @selection-change="handleSelectionChange"
                >
                    <edu-table-column
                        label="国际会议英文名称"
                        prop="englishName"
                        min-width="140"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="英文名称（缩写）"
                        prop="englishNameAbbreviation"
                        min-width="140"
                    ></edu-table-column>
                    <edu-table-column label="国际会议中文名称" prop="name" min-width="140" align="center"></edu-table-column>
                    <edu-table-column
                        label="会议级别"
                        prop="conferenceLevel"
                        min-width="110"
                        align="center"
                    >
                        <template slot-scope="scope">{{scope.row.conferenceLevel | meeting}}</template>
                    </edu-table-column>
                    <edu-table-column
                        label="会议申请时间"
                        prop="applyTime"
                        min-width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="会议开始时间"
                        prop="conferenceStartTime"
                        min-width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="会议结束时间"
                        prop="conferenceEndTime"
                        min-width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="实际出国时间"
                        prop="realLeaveTime"
                        min-width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="实际回国时间"
                        prop="realBackTime"
                        min-width="120"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column
                        label="会议审核状态"
                        prop="approveStatus"
                        min-width="120"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.approveStatus !== null"
                                :type="scope.row.approveStatus | getType"
                            >{{scope.row.approveStatus | approveStatus}}</el-tag>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        label="下一级审批人"
                        prop="approverName"
                        min-width="120"
                        align="center"
                    ></edu-table-column>

                    <edu-table-column label="操作" prop="idCard" min-width="150" align="center">
                        <template slot-scope="scope">
                            <el-button type="text" @click="toDetail(scope.row)">查看</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.approveStatus === 0 || scope.row.approveStatus === 4"
                                @click="editDetail(scope.row)"
                            >编辑</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.approveStatus === 1"
                                @click="approveRevoke(scope.row)"
                            >撤销</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.approveStatus === 0 || scope.row.approveStatus === 4"
                                @click="delApplication(scope.row)"
                            >删除</el-button>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        label="报销审核状态"
                        prop="reimbursementStatus"
                        min-width="150"
                        align="center"
                    >
                        <template slot-scope="scope">
                            <el-tag
                                v-if="scope.row.reimbursementStatus !==null"
                                :type="scope.row.reimbursementStatus | getType"
                            >{{scope.row.reimbursementStatus | reimbursementStatus}}</el-tag>
                        </template>
                    </edu-table-column>
                    <edu-table-column
                        label="报销下一级审批人"
                        prop="reimbursementapproverName"
                        min-width="150"
                        align="center"
                    ></edu-table-column>
                    <edu-table-column label="回国报销操作" prop="idCard" min-width="180" align="center">
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                v-show="scope.row.reimbursementStatus !== null"
                                @click="toRevDetail(scope.row)"
                            >查看</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.approveStatus === 3 && scope.row.reimbursementStatus === null"
                                @click="addRev(scope.row)"
                            >申请</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.reimbursementStatus === 0 || scope.row.reimbursementStatus === 4"
                                @click="editRevDetail(scope.row)"
                            >编辑</el-button>
                            <el-button
                                type="text"
                                v-show="scope.row.reimbursementStatus === 1"
                                @click="revRevoke(scope.row)"
                            >撤销</el-button>
                        </template>
                    </edu-table-column>
                </edu-table>
            </el-card>
        </div>

        <!-- 申请页面 -->
        <div v-if="ifShowList ===2">
            <inter-Aca-Conference-Application
                @returnVal="changekey"
                :studentInfo="studentInfo"
                :pgConferenceApply="pgConferenceApply"
                :pgExchangeHistory="pgExchangeHistory"
                :approveHistory="approveHistory"
                :ifShowDetail="ifShowDetail"
                :ifAdd="ifAdd"
                :file="file"
                :submitType="submitType"
                :countryList="countryList"
            ></inter-Aca-Conference-Application>
        </div>
        <!-- 报销页面 -->
        <div v-if="ifShowList ===3">
            <pro-Rep-And-Exp-Rei
                @returnVal="changekey"
                :ifShowDetail="ifShowDetail"
                :tranParm="tranParm"
            ></pro-Rep-And-Exp-Rei>
        </div>
    </div>
</template>
<script>
import appListOfIntAcaConApi from 'common/src/api/internationalCommunication/appListOfIntAcaCon'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import interAcaConferenceApplication from './interAcaConferenceApplication'
import proRepAndExpRei from './proRepAndExpRei'
export default {
    components: {
        'inter-Aca-Conference-Application': interAcaConferenceApplication,
        'pro-Rep-And-Exp-Rei': proRepAndExpRei
    },
    data() {
        return {
            dataList: [],
            ifShowList: 1, // 1:列表页  2：详情页  3：新增页
            studentInfo: {},
            pgConferenceApply: {},
            pgExchangeHistory: [],
            approveHistory: [],
            file: [],
            submitType: '',
            reimbursementId: '',
            tranParm: {
                conferenceStartTime: '',
                conferenceEndTime: '',
                id: '',
                studentId: '',
                submitType: '',
                realReadPosterTime: '',
                realReadPosterSubject: ''
            },
            multipleSelection: [],
            ifShowDetail: false,
            achievements: [],
            ifAdd: true,
            pageModel: {
                pageNum_: 1,
                pageSize_: 20,
                total_: 2
            },

            options: {
                conferenceLevel: [
                    { value: 1, label: '顶级会议' },
                    { value: 2, label: 'A类会议' },
                    { value: 3, label: 'B类会议' }
                ]
            },
            countryList: {
                country: []
            }
        }
    },
    filters: {
        meeting(val) {
            switch (val) {
                case 1:
                    return '顶级会议 '
                case 2:
                    return 'A类会议 '
                case 3:
                    return 'B类会议 '
                default:
                    return ' '
            }
        },
        approveStatus(val) {
            switch (val) {
                case 0:
                    return '草稿'
                case 1:
                    return '已提交'
                case 2:
                    return '待审核'
                case 3:
                    return '通过'
                case 4:
                    return '驳回'
                case 5:
                    return '不通过'
                default:
                    return ' '
            }
        },
        getType(val) {
            switch (val) {
                case 0:
                    return 'info'
                case 1:
                    return 'info'
                case 2:
                    return 'info'
                case 3:
                    return 'success'
                case 4:
                    return 'warning'
                case 5:
                    return 'danger'
                default:
                    return val
            }
        },
        reimbursementStatus(val) {
            switch (val) {
                case 0:
                    return '草稿'
                case 1:
                    return '已提交'
                case 2:
                    return '待审核'
                case 3:
                    return '通过'
                case 4:
                    return '驳回'
                default:
                    return ' '
            }
        }
    },
    created() {
        this.getListData()
    },

    methods: {
        changekey(val) {
            this.ifShowList = val
            this.getListData()
        },

        async getCountry() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'G_GJQU' // 国家/地区
                ]
            }
            await queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        country: 'G_GJQU' // 国家/地区
                    },
                    res.data,
                    this.countryList
                )
            })
        },

        // 获取列表页
        getListData() {
            this.dataList = []
            appListOfIntAcaConApi.getApplyList().then(res => {
                res.data.forEach(appList => {
                    this.dataList.push(appList)
                })
            })
            this.multipleSelection = []
        },
        handleSelectionChange(val) {
            this.multipleSelection = []
            val.forEach(app => {
                this.multipleSelection.push({ id: app.id, approveStatus: app.approveStatus })
            })
        },

        // 申请撤销
        approveRevoke(row) {
            let parm = [
                {
                    no: row.actNo,
                    content: '申请撤销'
                }
            ]
            this.$confirm('是否撤销?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                appListOfIntAcaConApi.approveRevoke(parm).then(res => {
                    if (res.code === 200) {
                        this.$message({
                            message: '撤销成功',
                            type: 'success'
                        })
                        this.getListData()
                    }
                })
            })
        },

        // 报销撤销
        revRevoke(row) {
            let parm = [
                {
                    no: row.reimbursementActNo,
                    content: '列表撤销'
                }
            ]
            this.$confirm('是否撤销?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                appListOfIntAcaConApi.revRevoke(parm).then(res => {
                    if (res.code === 200) {
                        this.$message({
                            message: '撤销成功',
                            type: 'success'
                        })
                        this.getListData()
                    }
                })
            })
        },

        // 获取申请信息
        async getDetail(id) {
            let _this = this
            await _this.getCountry()
            appListOfIntAcaConApi.getConferenceDetails(id).then(res => {
                if (res.data.studentInfo) {
                    _this.studentInfo = res.data.studentInfo
                }
                if (res.data.pgConferenceApply) {
                    _this.pgConferenceApply = res.data.pgConferenceApply
                }
                if (res.data.pgExchangeHistory) {
                    _this.pgExchangeHistory = res.data.pgExchangeHistory
                }
                if (res.data.approveHistory) {
                    _this.approveHistory = res.data.approveHistory
                }
                if (res.data.file) {
                    _this.file = res.data.file
                }
            })
        },
        // 跳转申请查看页
        toDetail(row) {
            this.getDetail(row.id)
            this.ifShowList = 2
            this.ifShowDetail = true
            this.ifAdd = true
            this.submitType = 'view'
        },

        // 跳转申请编辑页
        editDetail(row) {
            appListOfIntAcaConApi.getApplySwitch().then(resM => {
                if (resM.code === 200) {
                    this.getDetail(row.id)
                    this.ifShowList = 2
                    this.ifShowDetail = false
                    this.ifAdd = true
                    this.submitType = 'edit'
                }
            })
        },

        // 跳转新增申请页
        addApplication() {
            let _this = this
            this.$nextTick(() => {
                _this.getCountry()
            })

            let parm = {
                id: '',
                studentId: ''
            }
            appListOfIntAcaConApi.getApplySwitch().then(resM => {
                if (resM.code === 200) {
                    appListOfIntAcaConApi.getTip().then(resT => {
                        if (resT.data.flag === 0) {
                            this.$confirm('你有不合格课程，是否继续申请？', '提示', {
                                confirmButtonText: '确定',
                                cancelButtonText: '取消',
                                type: 'warning'
                            }).then(() => {
                                appListOfIntAcaConApi.getStudentInfo(parm).then(res => {
                                    if (res.code === 200) {
                                        for (let key in res.data) {
                                            _this.studentInfo[key] = res.data[key]
                                        }
                                        _this.ifShowList = 2
                                        _this.ifAdd = true
                                        _this.ifShowDetail = false
                                        _this.submitType = 'add'
                                    }
                                })
                            })
                        } else if (resT.data.flag === 1) {
                            appListOfIntAcaConApi.getStudentInfo(parm).then(res => {
                                if (res.code === 200) {
                                    for (let key in res.data) {
                                        _this.studentInfo[key] = res.data[key]
                                    }
                                    _this.ifShowList = 2
                                    _this.ifAdd = true
                                    _this.ifShowDetail = false
                                    _this.submitType = 'add'
                                }
                            })
                        }
                    })
                }
            })
        },

        // 删除报销申请
        delApplication(val) {
            let _this = this
            if (val) {
                this.multipleSelection = []
                this.multipleSelection.push({ id: val.id, approveStatus: val.approveStatus })
            }
            if (this.multipleSelection.length === 0) {
                _this.$message.error('请勾选数据')
            } else if (_this.multipleSelection.length > 0) {
                for (let i = 0; i < _this.multipleSelection.length; i++) {
                    if (
                        _this.multipleSelection[i].approveStatus !== 0 &&
                        _this.multipleSelection[i].approveStatus !== 4
                    ) {
                        _this.$message.error('只有草稿和驳回状态数据可删除')
                        return false
                    }
                }

                this.$delConfirm().then(_ => {
                    appListOfIntAcaConApi.deleteBatchList(_this.multipleSelection).then(res => {
                        if (res.code === 200) {
                            _this.$message({
                                message: '删除成功',
                                type: 'success'
                            })
                            _this.getListData()
                        }
                    })
                })
            }
        },

        // 跳转报销详情页
        toRevDetail(row) {
            this.tranParm.submitType = 'view'
            this.ifShowList = 3
            this.setParm(row)
            this.ifShowDetail = true
        },

        // 跳转报销编辑页
        editRevDetail(row) {
            this.ifShowList = 3
            this.ifShowDetail = false
            this.setParm(row)
            this.tranParm.submitType = 'edit'
        },
        // 新增报销申请
        addRev(row) {
            this.ifShowList = 3
            this.ifShowDetail = false
            this.tranParm.submitType = 'add'
            this.setParm(row)
        },
        // 报销传参
        setParm(row) {
            this.tranParm.conferenceEndTime = row.conferenceEndTime
            this.tranParm.conferenceStartTime = row.conferenceStartTime
            this.tranParm.realReadPosterTime = row.realReadPosterTime
            this.tranParm.realReadPosterSubject = row.realReadPosterSubject
            this.tranParm.id = row.id
            this.tranParm.studentId = row.studentId
            this.tranParm.reimbursementId = row.reimbursementId
        }
    }
}
</script>
<style lang="scss" scoped>
.condition-card ::v-deep {
    .el-row {
        height: 30px !important;
    }
    .el-form-item {
        margin-bottom: 0 !important;
    }
}
.roster-container ::v-deep {
    .el-date-editor--datetimerange.el-input__inner {
        width: 100% !important;
    }
    .el-form {
        padding-right: 15px;
    }
}
.condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
}
.sub-title {
    margin: 16px 0 65px 0;
    font-size: 16px;
    color: #000020;
    letter-spacing: 0;
}
</style>
